﻿#include "widget.h"
#include "ui_widget.h"
#include <QVBoxLayout>
#include <QPushButton>


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QVBoxLayout *layout = new QVBoxLayout(this);

    // 创建自定义进度条
    ProgressBar *progressBar = new ProgressBar(this);
    progressBar->setForegroundColor(QColor("#1e9fff")); // 蓝色
    progressBar->setBackgroundColor(QColor("#ff5722")); // 红色背景
    progressBar->setBorderRadius(5); // 圆角半径
    progressBar->setProgress(25); // 设置初始进度为 25%
    progressBar->setFixedHeight(50);

    // 创建按钮用于增加进度
    QPushButton *increaseButton = new QPushButton("增加进度", this);
    QObject::connect(increaseButton, &QPushButton::clicked, [progressBar]() {
        int progress = progressBar->getProgress() + 10;
        if (progress > 100) progress = 100;
        progressBar->setProgress(progress);
    });

    // 将控件添加到布局中
    layout->addWidget(progressBar);
    layout->addWidget(increaseButton);

    this->setLayout(layout);

}

Widget::~Widget()
{
    delete ui;
}

